package cn.itsource.pethome.pet.service.impl;

import cn.itsource.pethome.basic.query.BaseQuery;
import cn.itsource.pethome.basic.service.impl.BaseServiceImpl;
import cn.itsource.pethome.basic.util.PageList;
import cn.itsource.pethome.pet.domain.Pet;
import cn.itsource.pethome.pet.mapper.PetMapper;
import cn.itsource.pethome.pet.service.IPetServie;
import cn.itsource.pethome.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @description: 描述:
 * @date: 2020/8/25 11:55
 * @author: summer
 * version: 1.0
 */
@Service
public class PetServieImpl extends BaseServiceImpl<Pet> implements IPetServie {

    @Autowired
    private PetMapper petMapper;

    @Override
    public void onSale(List<Pet> pets,int status) {
        petMapper.updateState(pets, status);
    }

    @Override
    public void offSale(List<Pet> pets, int status) {
        petMapper.updateState(pets, status);
    }

    @Override
    public void adopt(Long id, User loginUser) {
        Pet pet = petMapper.loadById(id);
        //下架时间
        pet.setOffsaletime(new Date());
        //既然已经被领养，它要被下架了
        pet.setState(0);
        //此时此刻，该宠物不属于门店了
        pet.setShop(null);
        //设置领养人
        pet.setUser(loginUser);
        //修改宠物
        petMapper.update(pet);
    }
}
